package com.dao;

import com.entity.Td_tblPartyOrgDetail;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

public interface Td_tblPartyOrgDetailDao extends JpaRepository<Td_tblPartyOrgDetail,Integer>{

    /**
     * 根据id获取一条领导信息
     * @param id
     * @return
     */
    @Query(value = "select * from Td_tblPartyOrgDetail where fd_id=?",nativeQuery = true)
    public Td_tblPartyOrgDetail getById(int id);

    /**
     * 根据组织id查询出目前的所有领导
     * @param branchId 组织id
     * @return 0=职务名    1=用户名
     */
    @Query(value = "select fd_VLeaderName,fd_userName from Td_tblPartyOrgDetail where fd_BranchID=?",nativeQuery = true)
    public List<Object[]> getAllByBranchId(int branchId);

    /**
     * 根据组织id查询出目前的所有领导
     * @param branchId 组织id
     * @return
     */
    @Query(value = "select fd_VLeaderName,fd_userName from Td_tblPartyOrgDetail where fd_BranchID=?",nativeQuery = true)
    public List<Td_tblPartyOrgDetail> getLeaderByBranchId(int branchId);


    /**
     * 删除组织的所有领导
     * @param branchId 组织id
     * @return
     */
    @Query(value = "delete from Td_tblPartyOrgDetail where fd_BranchID=?",nativeQuery = true)
    @Modifying
    public int deleteByFd_BranchID(int branchId);

    /**
     * 查询某个党组织的书记
     * @param branchId 组织id
     * @return
     */
    @Query(value = "select * from Td_tblPartyOrgDetail where fd_VLeaderName='党支部书记' and fd_BranchID=?",nativeQuery = true)
    public Td_tblPartyOrgDetail getSecretaryByBranch(int branchId);
}
